package com.kaibes.web.util;

import javax.servlet.http.HttpServletRequest;

import com.kaibes.core.base.util.StringUtils;

public class WebPageUtils {

    public static String getPageUri(HttpServletRequest request) {
        String path = request.getQueryString();
        if (path != null) {
            path = path.replaceAll("(.*)(page=\\d+)(.*)", "$1$3");
            if (StringUtils.isBlank(path)) {
                return request.getRequestURI()+"?"+"page=";
            } else if (path.startsWith("&")) {
                path = path.substring(1);
            } else if (path.endsWith("&")) {
                path = path.substring(0, path.length()-1);
            } else {
                path = path.replaceAll("&&", "&");
            }
            return request.getRequestURI()+"?"+path+"&page=";
        } else {
            return request.getRequestURI()+"?"+"page=";
        }
    }
    
}
